package com.jyw.business.ast.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.jyw.business.ast.domain.vo.web.AstConsumableClaimReserveVo;
import com.jyw.business.ast.domain.vo.web.AstConsumableReserveRecordVo;
import com.jyw.common.utils.DateUtils;
import com.jyw.system.utils.ConversionUtil;
import org.springframework.stereotype.Service;
import com.jyw.business.ast.mapper.AstConsumableRecordMapper;
import com.jyw.business.ast.domain.AstConsumableRecord;
import com.jyw.business.ast.service.IAstConsumableRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 资产-耗材-记录Service业务层处理
 * 
 * @author system
 * @date 2023-10-24
 */
@Service
public class AstConsumableRecordServiceImpl extends ServiceImpl<AstConsumableRecordMapper,AstConsumableRecord> implements IAstConsumableRecordService
{
    @Resource
    private AstConsumableRecordMapper astConsumableRecordMapper;

    /**
     * 查询资产-耗材-记录
     * 
     * @param id 资产-耗材-记录主键
     * @return 资产-耗材-记录
     */
    @Override
    public AstConsumableRecord selectAstConsumableRecordById(Long id)
    {
        return astConsumableRecordMapper.selectAstConsumableRecordById(id);
    }

    /**
     * 查询资产-耗材-记录列表
     * 
     * @param astConsumableRecord 资产-耗材-记录
     * @return 资产-耗材-记录
     */
    @Override
    public List<AstConsumableRecord> selectAstConsumableRecordList(AstConsumableRecord astConsumableRecord)
    {
        return astConsumableRecordMapper.selectAstConsumableRecordList(astConsumableRecord);
    }

    /**
     * 新增资产-耗材-记录
     * 
     * @param astConsumableRecord 资产-耗材-记录
     * @return 结果
     */
    @Override
    public int insertAstConsumableRecord(AstConsumableRecord astConsumableRecord)
    {
        astConsumableRecord.setCreateTime(DateUtils.getNowDate());
        return astConsumableRecordMapper.insertAstConsumableRecord(astConsumableRecord);
    }

    /**
     * 修改资产-耗材-记录
     * 
     * @param astConsumableRecord 资产-耗材-记录
     * @return 结果
     */
    @Override
    public int updateAstConsumableRecord(AstConsumableRecord astConsumableRecord)
    {
        return astConsumableRecordMapper.updateAstConsumableRecord(astConsumableRecord);
    }

    /**
     * 批量删除资产-耗材-记录
     * 
     * @param ids 需要删除的资产-耗材-记录主键
     * @return 结果
     */
    @Override
    public int deleteAstConsumableRecordByIds(Long[] ids)
    {
        return astConsumableRecordMapper.deleteAstConsumableRecordByIds(ids);
    }

    /**
     * 删除资产-耗材-记录信息
     * 
     * @param id 资产-耗材-记录主键
     * @return 结果
     */
    @Override
    public int deleteAstConsumableRecordById(Long id)
    {
        return astConsumableRecordMapper.deleteAstConsumableRecordById(id);
    }

    @Override
    public List<AstConsumableReserveRecordVo> reserveRecord(Long id, String type) {
        List<AstConsumableRecord> list = lambdaQuery()
                .eq(AstConsumableRecord::getType, type)
                .eq(AstConsumableRecord::getConsumableId, id)
                .list();
        List<AstConsumableReserveRecordVo> collect = list.stream().map(data -> new AstConsumableReserveRecordVo(data)).collect(Collectors.toList());
        return ConversionUtil.conversionList(collect,AstConsumableReserveRecordVo.class);
    }

    @Override
    public List<AstConsumableClaimReserveVo> claimReserveRecord(Long id) {
        return ConversionUtil.conversionList(astConsumableRecordMapper.claimReserveRecord(id), AstConsumableClaimReserveVo.class);
    }
}
